package com.hxy.controller;

import com.github.pagehelper.PageInfo;
import com.hxy.common.JsonResult;
import com.hxy.pojo.Folk;
import com.hxy.pojo.Stuffinfo;
import com.hxy.pojo.Trainnote;
import com.hxy.pojo.vo.StuffVoResultMapAndTrainNote;
import com.hxy.pojo.vo.StuffinfoShowByIdVo;
import com.hxy.pojo.vo.StuffinfoVo;
import com.hxy.pojo.vo.TrainnoteVo;
import com.hxy.service.TrainNoteService;
import org.omg.CORBA.INTERNAL;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author hxy
 */
@RestController
@RequestMapping("/admin/trainNote")
public class TrainNoteController {

    @Autowired
    private TrainNoteService trainNoteService;

    @RequestMapping("/list")
    public JsonResult show(@RequestParam(value = "page", required = false, defaultValue = "1") Integer page,
                           @RequestParam(value = "limit", required = false, defaultValue = "10") int limit) {
        page = page == null ? 1 : page;
        PageInfo<Trainnote> trainnotePageInfo = trainNoteService.selectAll(page, limit);
        return new JsonResult(0, "成功", trainnotePageInfo);
    }

    /**
     *培训添加
     * @param trainNotevo
     * @return
     */
    @RequestMapping("/addTrainNote")
    public JsonResult addTrainNote(TrainnoteVo trainNotevo) {

        int i = trainNoteService.addTrainNote(trainNotevo);
        if (i>0){

            return new JsonResult(0,"添加成功",null);
        }else{
            return new JsonResult(1,"添加失败",null);
        }

    }

    /**
     *
     * @param page
     * @param limit
     * @param trainname
     * @param startTime
     * @param trainunit
     * @param status
     * @return
     */
    @RequestMapping("/findTrainnoteByTJ")
    public JsonResult findTrainnoteByTJ(@RequestParam(value = "page", required = false, defaultValue = "1") Integer page,
                                        @RequestParam(value = "limit", required = false, defaultValue = "10") Integer limit,
                                        @RequestParam(value = "name", required = false, defaultValue = "") String trainname,
                                        @RequestParam(value = "startTime", required = false, defaultValue = "") String startTime,
                                        @RequestParam(value = "trainunit", required = false, defaultValue = "") String trainunit,
                                        @RequestParam(value = "status", required = false, defaultValue = "") String status) {
        page = page == null ? 1 : page;
        PageInfo<TrainnoteVo> trainnotePageInfo = trainNoteService.findTrainnoteByTJ(page, limit,trainname,startTime,trainunit,status);
        return new JsonResult(0, "成功", trainnotePageInfo);
    }

    /**
     *
     * @param trainnotevo
     * @return
     */
    @RequestMapping("/updataTrainNote")
    public  JsonResult updataTrainNote(TrainnoteVo trainnotevo){

        int i = trainNoteService.updataTrainNote(trainnotevo);
        if (i>0){

            return new JsonResult(0,"修改成功",null);
        }else{
            return new JsonResult(1,"修改失败",null);
        }

    }
    @RequestMapping("/deleteTrainNote")
    public  JsonResult deleteTrainNote(Integer id){

        int i = trainNoteService.deleteTrainNote(id);
        if (i>0){

            return new JsonResult(0,"删除成功",null);
        }else{
            return new JsonResult(1,"删除失败",null);
        }

    }

    /**
     * 查xun一个
     * @param pageNo
     * @param id
     * @return
     */
    @RequestMapping("/findTrainnoteStu")
    public JsonResult findTrainnoteStu(@RequestParam(value = "page", required = false, defaultValue = "1") Integer pageNo,
                                       @RequestParam(value = "limit", required = false, defaultValue = "100") Integer limit,
                                       @RequestParam(value = "id", required = false) Integer id) {

        PageInfo<StuffinfoShowByIdVo> stuffinfoPageInfo = trainNoteService.findTrainnoteStu(id, pageNo, limit);

        return new JsonResult(0, "成功", stuffinfoPageInfo);
    }

    /**
     * 查询所有培训学员
     * @param pageNo
     * @return
     */
    @RequestMapping("/findTrainnoteAllStu")
    public JsonResult findTrainnoteAllStu(@RequestParam(value = "page", required = false, defaultValue = "1") Integer pageNo,
                                           @RequestParam(value = "limit", required = false, defaultValue = "10") Integer limit) {

        PageInfo<StuffVoResultMapAndTrainNote> stuffinfoPageInfo = trainNoteService.findTrainnoteAllStu(pageNo, limit);

        return new JsonResult(0, "成功", stuffinfoPageInfo);
    }

    /**
     * 回显单个培训记录
     * @param id
     * @return
     */
    @RequestMapping("/findTrainnoteOne")
    public JsonResult findTrainnoteOne(Integer id){
        JsonResult jsonResul= trainNoteService.findTrainnoteOne(id);
        return  jsonResul;
    }
//    @RequestMapping("/deleteTrainNote_IndexBytid")
    /**
     * 删除某个培训中的某个人员
     * @param Tid
     * @param Eid
     * @return
     */
    @RequestMapping("/deleteTrainNote_IndexByTidAndEid")
    public JsonResult deleteTrainNote_IndexByTidAndEid( Integer Tid, Integer Eid){
        JsonResult jsonResul= trainNoteService.deleteTrainNote_IndexByTidAndEid(Tid,Eid);
        return  jsonResul;
    }

    /**
     * 添加某人到某个培训
     * @param Tid
     * @param Eid
     * @return
     */
    @RequestMapping("/addTrainNote_IndexByTidAndEid")
    public JsonResult addTrainNote_IndexByTidAndEid( Integer Tid, Integer Eid){
        JsonResult jsonResul= trainNoteService.addTrainNote_IndexByTidAndEid(Tid,Eid);
        return  jsonResul;
    }


}
